﻿using Cms.Core.Infrastructure.Dependency;
using Cms.Core.Infrastructure.Extension;
using Cms.Core.Infrastructure.Helps;
using Cms.Core.Infrastructure.Reflection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Cms.Core.Infrastructure;
namespace Cms.Core.Infrastructure.Filter
{
    public class ScopedDependencyTypeFinder : FinderBase<Type>
    {
        private IAllAssemblyFinder AllAssemblyFinder { get; set; }

        public ScopedDependencyTypeFinder()
        {
            AllAssemblyFinder = new RuntimeHelper();
        }
        protected override Type[] FindAllItems()
        {
            Type baseType = typeof(IScopeDependency);
            Type[] types = AllAssemblyFinder.FindAll(fromCache: true).SelectMany(assembly => assembly.GetTypes())
                .Where(type => baseType.IsAssignableFrom(type) && !type.HasAttribute<IgnoreDependencyAttribute>() && !type.IsAbstract && !type.IsInterface)
                .ToArray();
            return types;
        }
    }
}
